/*
 *  Class name: UserServiceImpl.java
 *  Version: 1.0
 *  Date: 20.6.2014
 */

package cz.morosystems.personwebmanager.businesslayer.sevices.impl;

import cz.morosystems.personwebmanager.businesslayer.sevices.UserService;
import cz.morosystems.personwebmanager.persistencelayer.daos.UserDAO;
import cz.morosystems.personwebmanager.persistencelayer.entities.User;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Michal Ďuriš
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDAO userManager;
    
    public UserServiceImpl() {
    }

    public void setUserManager(UserDAO userManager) {
        this.userManager = userManager;
    }

    @Override
    public void addUser(User user) {
        userManager.addUser(user);
    }

    @Override
    public void changeUser(User user) {
        userManager.changeUser(user);
    }

    @Override
    public void deleteUser(Long userID) {
        userManager.deleteUser(userID);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<User> getAllUsers() {
        return userManager.getAllUsers();
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public User getUserByID(Long userID) {
        
        if(userID == null || userID < 1) {
            throw new IllegalArgumentException();
        }
        
        return userManager.getUserByID(userID);
    }
}
